<?php 
require "DataLoad.php"; 
CheckAdmin2();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">

</style>


</head>

<body>

<div class="header">
<?php require "menu.php"; ?>
<script type=text/javascript>
function eventselectclass() {
	var sclass=document.forms["eventadd"].event_class.value
	if (sclass=="加入" || sclass=="离开") {
		document.forms["eventadd"].object.className="action"
		document.forms["eventadd"].object2.className="unuse"
		document.forms["eventadd"].event_dkp.className="unuse"
		document.forms["eventadd"].event_dkp2.className="unuse"
	}
	else if (sclass=="拾取") {
		document.forms["eventadd"].object.className="action"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"
		document.forms["eventadd"].event_dkp2.className="action"
	}
	else if (sclass=="分解") {
		document.forms["eventadd"].object.className="unuse"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"		
		document.forms["eventadd"].event_dkp2.className="unuse"
	}
	else if (sclass=="发现" || sclass=="首次" || sclass=="击杀") {
		document.forms["eventadd"].object.className="unuse"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"		
		document.forms["eventadd"].event_dkp2.className="unuse"
	}
	else if (sclass=="职务任命") {
		document.forms["eventadd"].object.className="action"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"
		document.forms["eventadd"].event_dkp2.className="unuse"
	}
	else if (sclass=="团队事件") {
		document.forms["eventadd"].object.className="unuse"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"
		document.forms["eventadd"].event_dkp2.className="unuse"
	}
	else if (sclass=="个人事件") {
		document.forms["eventadd"].object.className="action"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"
		document.forms["eventadd"].event_dkp2.className="unuse"
	}	else {
		document.forms["eventadd"].object.className="unuse"
		document.forms["eventadd"].object2.className="action"
		document.forms["eventadd"].event_dkp.className="action"		
		document.forms["eventadd"].event_dkp2.className="unuse"
	}}

var currentActiveTab = "menuB";

</script>
</div>
<div class="main">
<?php 
switch ($_GET["action"]) {
	case "step1sql":
		step1sql();
		break;
	case "add":
		raidplan_addsql();
		break;
	case "del":
		raidplan_delsql();
		break;
	case "collect":
		raid_collect1();
		//默认列表未结束的活动
		break;
	case "collect2":
		raid_collect2();
		break;
	default:
		raid_list();
		break;
} 
?>
</div>
<?php require "footer.php"; ?>
</body>
</html>
<?php 

function raid_collect1() {
	if (!is_numeric($_GET["id"])) {
		return false; 
	} 
	$sql="select * from raid where id=".$_GET["id"];
	if ($result = mysql_query($sql)) {
		//活动信息收集
		//参加人员
		$row = mysql_fetch_array($result);
		cboxmember2("all","",$row["raid_player"]);
	}
	return;
}



function raid_collect2() {
	//echo "work";
	//活动事件添加
	$sql="select * from raid where id=".$_GET["id"];

	if (!$result = mysql_query($sql)) return false;
	$row = mysql_fetch_array($result);
	$sdate=$row["raid_actiontime"];
	//表单
	print "<form name='eventadd' action='admin_eventadd.php?action=add' method='post'>";
	print "<table class='reportform outframe'>";
	print "<tr><th colspan='6'>添加事件</th></tr>";
	print "<tr class='coltitle'><td>时间</td><td>类型</td><td>对象/描述</td><td>分数</td><td>分数2</td><td></td></tr>";
	print "<tr><td>".selecteventdate($sdate,"")."<input type='text' name='event_time' size='14' value='{$sdate}:".strftime("%M",$sdate)."' /></td><td>".eventclass("")."</td> <td>".raidmemberselect($_GET['id'],"")."<input type='' class='unuse' name='object2' value=''  size='14'/></td>";
	print " <td><input type='text' class='unuse' name='event_dkp' value='' size='6'/></td><td><input type='text' class='unuse' name='event_dkp2' value='' size='6'/></td><td><input type='submit' value='添加'/><input type='hidden' name='postid' value='".$_GET['id']."' /></td></tr>";
	print "</table>";
	print "</form>";

	//已有事件列表
	if (!is_numeric($_GET["id"])) return false;

	$sql="select * from raid_event where event_raidid=".$_GET["id"]." order by event_time";
	if ($result = mysql_query($sql)) {
		//活动信息收集
		//参加人员
		print "<h4></h4>";
		print "<table class='eventlist outframe interlace hasfocus'>";
		print "<tr><th colspan='7'><div class='title'><img src='images/icon/banner.jpg'>事件列表</div><div class='filter'>[<a href='raid_report.php?id=".$_GET["id"]."'>查看报告</a>]</div></th></tr>";
		print "<tr class='coltitle'><td>时间</td><td>玩家</td><td>类型</td> <td>对象/描述</td> <td>分数</td><td>拾取分配</td> <td>操作</td></tr>";
		while ($row = mysql_fetch_array($result)) {
			print "<tr><td>".$row["event_time"]."</td><td>".id2name($row["event_object"])."</td> <td>".getEventIco($row["event_class"]).$row["event_class"]."</td>  <td>".$row["event_object2"]."</td><td>".$row["event_dkp"]."</td> <td>".$row["event_dkp2"]."</td><td><a href='admin_event_edit.php?id=".$row["id"]."&rid=".$_GET["id"]."' >修改</a> <a href='admin_eventadd.php?action=del&id=".$row["id"]."'>删除</a></td></tr>";
		}
		print "</table>";
		print "<div class='message'>物品名称后面的\"#数字\"是物品的ID编号,如果删除将不能读取官方Armory.</div>";
	}

	return;
} 

function raid_collect3() {
	//活动信息收集
	//发生事件
	return;
} 

function step1sql() {
	//验证提交数据有效性
	//数据库字段:
	//if request("raid_name")="" then errorinfo=errorinfo & "<li>活动名称请不要留空.</li>"
	//if not IsDate(request("raid_concentratetime")) then errorinfo=errorinfo & "<li>集结的时间格式不正确,请参考旁边的格式</li>"
	//if not IsDate(request("raid_actiontime")) then errorinfo=errorinfo & "<li>行动的时间格式不正确,请参考旁边的格式</li>"
	//if not IsNumeric(request("raid_personnel")) then errorinfo=errorinfo & "<li>人员数量必须为数字</li>"
	//if request("ruler_name")="" then errorinfo=errorinfo & "<li>请选择一个DKP规则,如果没有请先建立.</li>"
	//if IsValidEmail(request("L_AuthorMail"))<>"true" and request("L_AuthorMail")<>"" then errorinfo=errorinfo & "<li>无效的邮箱地址.</li>"
	//验证///

	if ($errorinfo!="") {
		//抛出错误提示
		print "<p>表单信息有误,提示如下:</p><ul>".$errorinfo."</ul>";
		print "请<a href='".$Url."'>返回</a>重新修改.";
	}else{
		//写入数据库
		$sql="update * from raid where id=".$_POST["postid"];
		$result = mysql_query($sql);
		$result["raid_player"]=$_POST["raid_player"];
		if ($result["raid_step"]!=3) {
			$result["raid_step"]=1;
		}
		print "<div class='message'><h3>参加人员指定完成</h3><div><a href='".$Url."' class='abtn2'>继续添加</a> <a href='admin_report.php?action=collect2&id=".$_POST["postid"]."' class='abtn3'>编辑活动事件</a> <a href='admin_report.php' class='abtn3'>查看列表</a> | <a href='raid_report.php?id=".$_POST["postid"]."' class='abtn'>查看该活动报告</a>";
		print "</div></div>";
	} 

	//删除
	$sql="Delete * from dkplist where raidid=".${"postid"};
	mysql_query($sql);
	return $function_ret;
} 




//t 职业		m		arr 选中数值序列
function cboxmember($t,$m,$arr) {
	$sql="select * from player where player_class='".$t."' Order by player_name";
	$pcode="<ol id='playerlist'><h3>".$t."</h3>";
	if ($result2 = mysql_query($sql)) {
		while ($row2 = mysql_fetch_array($result2)) {
			$pcode .= "<li><input type='checkbox' name='raid_player' value='".$row2["id"]."' ".memberchecked($row2["id"],$arr)." />".$row2["player_name"]."</li>";
		}
	}else{
		$pcode .= "<li>没有此职业成员</li>";
	}
	$pcode .= "</ol>";
	return $pcode;
} 

function prof2style($pro) {
	switch ($pro) {
		case "战士":
			$function_ret="warrior";
			break;
		case "牧师":
			$function_ret="priest";
			break;
		case "法师":
			$function_ret="mage";
			break;
		case "盗贼":
			$function_ret="rogue";
			break;
		case "猎人":
			$function_ret="hunter";
			break;
		case "圣骑士":
			$function_ret="paladin";
			break;
		case "萨满":
			$function_ret="shaman";
			break;
		case "术士":
			$function_ret="warlock";
			break;
		case "德鲁依":
			$function_ret="druid";
			break;
		default:

			$function_ret="unknow";
			break;
	} 
	return $function_ret;
} 

//t 职业		m		arr 选中数值序列
function cboxmember2($t,$m,$arr) {
	global $ArrTF;
	print "<form action='?action=step1sql' method='post'><table class='playselecttable outframe'><tr>";
	print "<th colspan='10'><input type='submit' value='完成人员指定' /></th></tr><tr>";
	foreach ($ArrTF as $class) {
		print "<td><dl><dt>".ProPic(end($class))." ".$class[0]."</dt>";
		$sql="select * from player where player_class = '{$class[0]}' order by player_raidnum desc , player_lastraid desc";
		if ($result2 = mysql_query($sql)) {
			while ($row2 = mysql_fetch_array($result2)) {
				print "<dd class='".memberchecked($row2["id"],$arr)."'><input type='checkbox' name='raid_player' value='".$row2["id"]."' ".memberchecked($row2["id"],$arr)." />".$row2["player_name"]."</dd>"."\r\n";
			}
		}else{
			print "没有该职业成员 $sql";
		}
		print "</dl></td>";
	}
	print "</tr><tr><th colspan='10'><input type='hidden' name='postid' value='".$_GET['id']."' /><input type='submit' value='完成人员指定' /></th>";
	print "</tr></table></form>";
	return;
} 

//t 职业		m		arr 选中数值序列
function raidmemberlist($id) {
	$sql="select * from player where player_class='".$t."' Order by player_name";
	$pcode="<h4>".$t."</h4><ul>";
	if ($result2 = mysql_query($sql)) {
		while ($row2=mysql_fetch_array($result2)) {
			$pcode=$pcode."<li><input type='checkbox' name='raid_player' value='".$row2["id"]."' ".memberchecked($row2["id"],$arr)." />".$row2["player_name"]."</li>";
		}
	}else{
		$pcode=$pcode."<li>没有此职业成员</li>";
	}
	$pcode .= "</ul>";
	return $pcode;
} 


//找出arr序列中时候包含id ,真则返回"checked"
function memberchecked($id,$arr2) {
	if (is_numeric($id)) {$id = id2name2($id);};
	$arrPlayers = explode(',',$arr2);
	if (in_array($id,$arrPlayers)) {
		return "checked";
	}else{
		return false;
	}
} 

function raid_list() {
	print "			<table class='adminlist outframe interlace'>";
	print "			<tr>";
	print "			<th colspan='6'><div class='title'><img src='images/icon/banner.jpg'>活动列表</div><div class='filter'>".selectraid2()."</div></th>";
	print "			</tr>";
	print "			<tr class='coltitle'>";
	print "				<td width='29px'>-</td>";
	print "				<td>分类</td>";
	print "				<td width='40%'>活动</td>";
	print "				<td>操作</td>";
	print "				<td>时间</td>";
	print "				<td>状态</td>";
	print "			</tr>"."\r\n";

	if ($_POST["filter"]!="") {
		switch (true) {
			case $_POST["filter"]="all":
			$sql="select * from raid Order by raid_actiontime desc";
			break;
			case $_POST["filter"]="edit":
			$sql="select * from raid where raid_step<1 or raid_class=0 Order by raid_actiontime desc";
			break;
			case $_POST["filter"]="end":
			$sql="select * from raid where raid_step>1 Order by raid_actiontime desc";
			break;
			case       $left[$_POST["filter"]][1]="D":
			$sql="select * from raid where raid_class=".substr($_POST["filter"],1)." Order by raid_actiontime desc";
			break;
			case       $left[$_POST["filter"]][1]="R":
			$sql="select * from raid where raid_ruler='".substr($_POST["filter"],1)."' Order by raid_actiontime desc";
			break;
		} 
	}else{
		$sql="select * from raid where raid_step<2 Order by raid_actiontime desc";
		
	} 

	//$sql="select * from raid order by id";
	if (!$result_raid = mysql_query($sql)) {
		print "<tr><td colspan='6' >没有找到链接项</td></tr>";
	}else{
		while($row = mysql_fetch_array($result_raid)) {
			print "<tr>";
			print "	<td>".getInstanceIco($row["raid_name"])."</td>";
			print "	<td>".getRaidClassText($row["raid_class"])."</td>";
			print "	<td><h5><a href='raid_report.php?id=".$row["id"]."'>".$row["raid_name"]."</a></h5><span>".$row["raid_plan"]."</span></td>";
			print "	<td>".opbtn($row["id"])."</td>";
			print "	<td>".$row["raid_actiontime"]."</td>";
			print "	<td>".oplink($row["id"])."</td>";
			print "</tr>"."\r\n";
		}
	} 

	$result->close;
	//response.write "<tr><td colspan='6' ><a href=''>查看更多活动记录</a></td></tr>"
	print "</table>";
	return;
} 




function opbtn($id) {
	$sql="select * from raid where id=".$id;
	if (!$result2 = mysql_query($sql)) return;
	$row = mysql_fetch_array($result2);
	$txt.= "<span>[";
	if ($row["raid_step"]>1) {
		$txt.= "基本信息";
	}else{
		$txt.= "<a href='admin_raid.php?action=edit&id=".$id."'>基本信息</a>";
	} 


	if ($row["raid_step"]>1) {
		$txt.= "-参加人员";
	}else{
		$txt.= "-<a href='?action=collect&id=".$id."'>参加人员</a>";
	} 

	if ($row["raid_step"]>1 || $row["raid_step"]==0) {
		$txt.= "-活动事件]";
	}else{
		$txt.= "-<a href='?action=collect2&id=".$id."'>活动事件</a>]";
	} 

	if ($row["raid_step"]<1) {
		$txt.= "-查看报告";
	}else{
		$txt.= "-<a href='raid_report.php?id=".$id."' class='abtn'>查看报告</a>";
	} 

	if ($_SESSION['leve']<2) {
		if ($row["raid_step"]>1) {
			$txt.= "-[归档";
		}else{
			$txt.= "-[<a href='raid_end.php?id=".$id."' class='abtn3'>归档</a>";
		} 
		if ($_SESSION['level']==0) {
			$txt.= "-<a href ='admin_raid.php?action=del&id=".$row['id']."' onclick=\"javascript:return(confirm('确定要删除这个活动吗？'))\" class='abtn4'>删</a>";
		} 
		$txt.= "]";
	} 
	$txt.= "</span>";
	return $txt;
} 


function oplink($id) {
	if (!is_numeric($id)) {
		return false;
	} 
	$sql="select * from raid where id=$id";
	if ($result = mysql_query($sql)) {
		$row = mysql_fetch_array($result);
		if ($row["raid_player"]=="" || $row["raid_step"]==0) {
			$optext .= "<li>未添加人员信息</li>";
		} 
		if ($row["raid_step"]==0) {
			$optext .= "<li>未添加活动事件</li>";
		} 
		if ($row["raid_step"]>1) {
			$optext .= "<li>已归档,只可查看报告</li>";
		} 
		if ($row["raid_class"]==0 || $row["raid_class"]=="") {
			$optext .= "<li>活动未设置DKP分类</li>";
		} 
		if ($optext!="") {
			$optext = "<ul class='status'>".$optext."</ul>";
		} 
		return $optext;
	}else{
		return false;
	}
} 

/*
function oplink2($id) {
	$step1="<a href='?action=collect&id=".$id."'>人员</a> - <a href='?action=collect2&id=".$id."'>事件</a> - <a href='raid_report.php?id=".$id."'>报告</a>";
	if (!is_numeric($id)) {
		return false;
	} 
	$sql="select * from raid where id=".$id;
	if ($result2 = mysql_query($sql)) {
		switch (true) {
		case       $result2["raid_step"]=1;:
			break;
		case       $result2["raid_step"]=0;:
			break;
		case       $result2["raid_step"]>1;:
			break;
		}

		if ($result2["raid_step"]==1) {
			$step1="<a href='?action=collect&id=".$id."'>人员</a> - <a href='?action=collect2&id=".$id."'>事件</a> - <a href='raid_report.php?id=".$id."'>报告</a>";
		}elseif ($result2["raid_step"]==0) {
			$step1="<a href='?action=collect&id=".$id."'>人员</a> - 事件 - 报告";
		}elseif ($result2["raid_step"]>1) {
			$step1="人员 - 事件 - <a href='raid_report.php?id=".$id."'>报告</a>";
		} 
	} 


	if ($result2["raid_step"]>1) {
		$function_ret="[ ".$step1." ]<br/>"."[ 修改 - <a href='admin_raid.php?action=del&id=".$result["id"]."'>删除</a> - 已归档 ]";
	}else{
		$function_ret="[ ".$step1." ]<br/>"."[ <a href='admin_raid.php?action=edit&id=".$result["id"]."'>修改</a> - <a href='admin_raid.php?action=del&id=".$result["id"]."'>删除</a> - <a href='raid_end.php?id=".$id."'>归档</a> ]";
	} 
	return $function_ret;
} 
*/



?>
